<!-- 下属单位评价页面 -->
<template>
  <div class="appraise-container">
    <!--头部标题-->
    <el-form class="form-header" ref="form" :model="form" label-width="100px">
      <el-form-item label="项目名称" prop="extractItem">
        <el-input
          class="commonWidth"
          size="small"
          placeholder="请输入项目名称"
          v-model="queryParams.extractItem"
          @keyup.enter.native="handleQuery"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="抽取人单位" prop="createBy">
        <el-select
          v-model="form.createBy"
          placeholder="请选择抽取人单位"
          clearable
          size="small"
          style="width: 100%"
          @change="UnitTypeChangepenson"
        >
          <el-option
            v-for="type in unitTypeponsonOptions"
            :key="type.userId"
            :label="type.nickName"
            :value="type.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="抽取库" prop="randomUnittypeId">
        <el-select
          class="commonWidth"
          v-model="form.randomUnittypeId"
          placeholder="请选择单位库"
        >
          <el-option
            v-for="item in form.extractData"
            :key="item.unittypeId"
            :label="item.unittypeName"
            :value="item.unittypeId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="btns">
        <el-button
          class="search-btn"
          icon="el-icon-search"
          type="primary"
          size="mini"
          @click="onSearch"
          >搜索</el-button
        >
        <el-button class="el-icon-refresh" size="mini" @click="reset"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
    </el-row>
    <!--表格内容-->
    <el-table
      :data="articleList"
      @current-change="currentRowChange"
      style="width: 100%"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="extractItem" align="left" label="项目名称" />
      <el-table-column label="建设地址" align="left" prop="extractAddress" />
      <el-table-column
        label="抽取人单位"
        align="left"
        prop="createBy"
        width="250"
      />
      <el-table-column
        prop="extractPrice"
        align="left"
        label="工程费用（万元）"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.extractPrice }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="中介机构服务费（万元）"
        align="left"
        prop="maxPrice"
      />
      <el-table-column
        prop="unitTypeName"
        label="抽取库"
        width="200"
      ></el-table-column>
      <el-table-column
        prop="extractApproveStatus"
        align="center"
        label="是否正常完成"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.extractApproveStatus | formatStatus }}</div>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="makeSureTime" />
      <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="loadExtractArticle(scope.row)"
            >项目查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="loadExtractReview(scope.row)"
            icon="el-icon-s-comment"
            >项目评价</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="pagination">
      <el-pagination
        :current-page.sync="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        :disabled="isPaginationDisabled"
        @current-change="currentChange"
        @size-change="handleSizeChange"
      />
    </div>
    <!--dialog项目评价弹窗-->
    <el-dialog
      title="项目详情"
      :visible.sync="commentDialogVisible"
      width="60%"
      @close="closeCommentDialog"
      :close-on-click-modal="false"
    >
      <quotationConfirm
        class="tableComponent"
        :quotationConfirm="quotationConfirm"
      />
      <quotationConfirm class="tableComponent" :quotationConfirm="price" />
      <simpleTable :simpleTableData="simpleTableData"></simpleTable>
      <!--评分扣分具体事项-->
      <!-- <div class="score-wrap">
				<div class="time-wrap">
					<div class="begin-time">
						<label>项目开始时间</label>
						<div class="remain">2021-11-25</div>
					</div>
					<div class="end-time">
						<label><i class="must">*</i>结束时间</label>
						<el-date-picker class="remain" v-model="saveData.endDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择时间（YYYY-MM-DD）" />
					</div>
				</div>
				<div class="select-file">
					<label><i class="must">*</i>评分表</label>
					<el-upload
						class="remain"
                        ref="uploadFile"
						:accept="acceptType"
						:limit="3"
						:on-exceed="onExceed"
						action=""
						:on-remove="handleRemove"
						:before-remove="beforeRemove"
						:http-request="uploadFile"
						:file-list="fileList"
					>
						<el-button size="small" type="primary">点击上传</el-button>
						<div slot="tip" class="el-upload__tip">
							请上传bmp，gif，jpg，jpeg，png，doc，docx，xls，xlsx，ppt，pptx，html，htm，txt，rar，zip，gz，bz2，pdf文件，且不超过10MB
						</div>
						<div class="uploadimg-wrap" v-if="imgUrl.length > 0">
							<el-image class="uploadimg" v-for="(item, index) in imgUrl" :key="index" style="width: 100px; height: 100px" :src="item" fit="cover" />
						</div>
					</el-upload>
				</div>
				<!--违规扣分-->
      <!-- <div class="deduction-wrap">
					<label><i class="must">*</i>违规扣分</label>
					<ul class="remain">
						<li v-for="(item, index) in saveData.radioList" :key="index">
							<div class="deduction-title">{{ item.ruleName }}</div>
							<el-radio v-model="item.whetherDeduct" label="0">是</el-radio>
							<el-radio v-model="item.whetherDeduct" label="1">否</el-radio>
						</li>
					</ul>
				</div> -->
      <!-- <div class="deduction-reason-wrap">
					<label><i class="must">*</i>扣分原因</label>
					<textarea class="remain" v-model="saveData.deductReason" cols="30" rows="10"></textarea>
				</div> -->
      <!-- </div> -->
      <!--底部按钮-->
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveInfo">确定</el-button>
        <el-button @click="commentDialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
    <!--dialog单位详情弹窗-->
    <!-- <el-dialog title="单位详情" :visible.sync="detailDialogVisible" width="60%"
      ><quotationConfirm :quotationConfirm="unitInfo"></quotationConfirm
    ></el-dialog> -->
    <DetailDialog :visible.sync="detailDialogVisible" :formUnit="unitInfo" />
    <el-dialog
      title="项目评价"
      :visible.sync="reviewVisible"
      width="60%"
      :close-on-click-modal="false"
    >
      <simpleTable :simpleTableData="simpleTableData"></simpleTable>
      <!--评分扣分具体事项-->
      <div class="score-wrap">
        <el-row style="margin-bottom: 10px">
          <el-col :span="12">
            <label style="margin-left: 10px">是否正常结束</label>
            <el-radio-group v-model="reviewRow.isNormal">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-col>
        </el-row>
        <div class="time-wrap">
          <div class="begin-time" style="margin-left: 18px">
            <label><i class="must">*</i>项目开始时间</label>
            <el-date-picker
              class="remain"
              v-model="saveItem.projectStartTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择时间（YYYY-MM-DD）"
              :disabled="reviewRow.isNormal == 1"
            />
          </div>
          <div class="end-time">
            <label><i class="must">*</i>项目结束时间</label>
            <el-date-picker
              class="remain"
              v-model="saveItem.projectEndTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择时间（YYYY-MM-DD）"
              :disabled="reviewRow.isNormal == 1"
            />
          </div>
        </div>
        <div>
          <el-row class="cash-end">
            <el-col :span="12">
              <label
                ><i
                  class="must"
                  style="
                    position: absolute;
                    top: 50%;
                    left: -10px;
                    transform: translateY(-50%);
                  "
                  >*</i
                >结算金额（万元）</label
              >
              <el-input-number
                v-model="reviewRow.settleAmount"
                :min="0"
                :max="10"
                controls-position="right"
                style="width: 220px"
                :disabled="reviewRow.isNormal == 1"
              />
            </el-col>
          </el-row>
        </div>
        <!--违规扣分-->
        <div>
          <span class="current-score"
            >当前扣分值：{{ currentDeductScore() }}分</span
          >
        </div>
        <div class="deduction-wrap">
          <label><i class="must">*</i>违规扣分</label>
          <ul class="remain">
            <li v-for="(item, index) in saveData.radioList" :key="index">
              <div class="deduction-title">{{ item.ruleName }}</div>
              <el-radio
                v-model="item.whetherDeduct"
                label="0"
                :disabled="reviewRow.isNormal == 1"
                >是</el-radio
              >
              <el-radio
                v-model="item.whetherDeduct"
                label="1"
                :disabled="reviewRow.isNormal == 1"
                >否</el-radio
              >
            </li>
          </ul>
        </div>
        <div class="select-file">
          <label><i class="must">*</i>评分表</label>
          <el-upload
            class="remain"
            ref="uploadFile"
            :accept="acceptType"
            :limit="1"
            :on-exceed="onExceed"
            action=""
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :http-request="uploadFile"
            :file-list="reviewFile"
            :disabled="reviewRow.isNormal == 1"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              请上传bmp，gif，jpg，jpeg，png，doc，docx，xls，xlsx，ppt，pptx，html，htm，txt，rar，zip，gz，bz2，pdf文件，且不超过10MB
            </div>
            <div class="uploadimg-wrap">
              <el-image
                class="uploadimg"
                v-for="(item, index) in reviewImg"
                :key="index"
                style="width: 100px; height: 100px"
                :src="item"
                fit="cover"
              />
            </div>
          </el-upload>
        </div>
        <div class="deduction-reason-wrap">
          <label>{{ reviewRow.isNormal == 1 ? "原因" : "备注" }}</label>
          <textarea
            class="remain"
            v-model="saveItem.deductReason"
            cols="30"
            rows="10"
          ></textarea>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveReview">保存</el-button>
        <el-button @click="reviewVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import quotationConfirm from "@/common/operation/quotationConfirm";
import simpleTable from "@/common/operation/simpleTable";
import { getUnit } from "@/api/unit/unit.js";
import { listUser } from "@/api/system/user";
import {
  getExtractOption,
  getExtractList,
  getExtractArticle,
  getScore,
  saveDeduction,
  Department,
  exportExtract,
} from "@/api/unit/extract";
import { evaluate } from "@/api/unit/extract";
import { listUnittype } from "@/api/unit/unittype";
import service from "../../components/utils/request.js";
import DetailDialog from "@/common/detailDialog";

export default {
  name: "appraise",
  components: {
    quotationConfirm,
    simpleTable,
    DetailDialog,
  },
  data() {
    return {
      // 单位类型字典
      unitTypeOptions: [],
      extractId: null,
      commentDialogVisible: false, // 是否打开项目评价弹窗
      detailDialogVisible: false, // 是否打开查看详情弹窗
      isPaginationDisabled: false, // 是否禁用分页
      currentPage: 1,
      //抽取人单位字典
      unitTypeponsonOptions: [],
      // 传给quotationConfirm的数据
      quotationConfirm: [
        {
          name: "项目名称",
          detailInfo: "重庆市金凤街道改造项目一期工程",
          showTwo: true,
          require: false,
        },
        {
          name: "建设地址",
          detailInfo: "重庆市九龙坡区金凤街道",
          showTwo: true,
        },
        {
          name: "工程费用（万元）",
          detailInfo: "1000",
          showTwo: true,
        },
        {
          name: "建设周期",
          detailInfo: "24个月",
          showTwo: true,
        },
        {
          name: "经办人",
          detailInfo: "张三",
          showTwo: true,
        },
        {
          name: "联系电话",
          detailInfo: "13922224444",
          showTwo: true,
        },
      ],
      price: [
        {
          name: "暂定中介服务费（万元）",
          detailInfo: "重庆市金凤街道改造项目一期工程",
          showTwo: true,
          require: false,
        },
        {
          name: "抽  取  人",
          detailInfo: "重庆市九龙坡区金凤街道",
          showTwo: true,
        },
        {
          name: "抽取地点",
          detailInfo: "1000",
          showTwo: true,
        },
        {
          name: "报价限制时间",
          detailInfo: "24个月",
          showTwo: true,
        },
        {
          name: "排除要求",
          detailInfo: "张三",
          showTwo: true,
        },
        {
          name: "备       注",
          detailInfo: "13922224444",
          showTwo: true,
        },
        {
          name: "抽  取  库",
          detailInfo: "13922224444",
          showTwo: true,
        },
      ],
      // 点击表格展示的公司信息
      currentObj: [],
      simpleTableData: {
        title: ["单位名称", "状态", "操作"], //使用方传， 组件第一个li里面的div的循环数据
        list: [],
      },
      form: {
        extractItem: "",
        extractUser: "",
        randomUnittypeId: "",
        extractData: [], //抽取库数据，
        userId: "",
        extractId: "",
        extractSignUrl: "",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        extractItem: null,
        extractUser: null,
        extractAddress: null,
        extractPrice: null,
        extractApproveStatus: null,
        maxPrice: null,
        randomUnittypeId: null,
        userId: null,
      },
      articleList: [], //表格列表
      pageSize: 10, //分页大小
      totalSize: 0, // 数据总条数
      pageSizes: [10, 20, 30, 50],
      pageNum: 1, // 数据页码
      // 上传文件列表地址
      fileList: [],
      // 接受的文件类型
      acceptType:
        "bmp,gif,jpg,jpeg,png,doc,docx,xls,xlsx,ppt,pptx,html,htm,txt,rar,zip,gz,bz2,pdf",
      // 图片类型
      imageType: "bmp,gif,jpg,jpeg,png",
      // 上传文件的图片地址
      imgUrl: [],
      // 传值给quotationComfirm组件展示
      unitInfo: [],
      //  提交给后台的数据
      saveData: {
        fileUrl: [],
        endDate: "", // 选择日期
        deductReason: "", // 扣分原因
        radioList: [],
      },
      // 当前行数据
      currentRow: {},
      reviewRow: {},
      saveItem: {
        deductReason: "",
      },
      companyInfo: [],
      reviewVisible: false,
      simpleTableData: {
        title: ["单位名称", "状态", "操作"], //使用方传， 组件第一个li里面的div的循环数据
        list: [],
      },
      reviewFile: [],
      reviewImg: [],
    };
  },
  created() {
    listUnittype(this.unitTypeParams).then((response) => {
      this.unitTypeOptions = response.rows;
    });
    this.loadExtractOption();
    this.loadExtractList();
    listUser().then((response) => {
      this.unitTypeponsonOptions = response.rows;
    });
  },
  methods: {
    //抽取人单位
    UnitTypeChangepenson(value) {
      listUser().then((response) => {
        for (var o = 0; o < response.rows.length; o++) {
          if (value == response.rows[o].userId) {
            this.queryParams.createBy = response.rows[o].nickName;
            console.log(this.queryParams.createBy);
          }
        }
      });
    },
    // 单位库类型翻译
    unitTypeFormat(row, column) {
      return this.selecttypeLabel(this.unitTypeOptions, row.randomUnittypeId);
    },
    // 点击搜索按钮
    onSearch() {
      this.loadExtractList();
    },
    // 改变页码显示不同的数据
    currentChange(page) {
      this.queryParams.pageNum = page;
      this.loadExtractList();
    },
    // 点击重置
    reset() {
      this.queryParams.extractItem = null;
      this.form.extractUser = null;
      this.form.randomUnittypeId = null;
      if (this.form.createBy != null) {
        this.form.createBy = null;
      }
      this.queryParams.createBy = null;
      this.loadExtractList();
      this.form.extractId = "";
      this.form.extractApproveStatus = "";
      this.form.ProjectAmount = "";
    },
    // 每页显示的数据条数改变
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.currentPage = 1;
      this.queryParams.pageNum = 1;
      this.loadExtractList();
    },
    // 去到项目评价弹窗
    goDialog() {},
    // 获取抽取库数据
    async loadExtractOption() {
      const res = await getExtractOption();
      try {
        if (res.code === 200) {
          this.form.extractData = res.rows.map((item) => {
            return item;
          });
        } else {
          this.$message.error(res.msg);
        }
      } catch (e) {
        this.$message.error(e);
      }
    },
    //获取表格列表数据
    async loadExtractList() {
      await Department().then((response) => {
        this.form.userId = response.data.userId;
      });
      //this.tableLoading = true;
      this.isPaginationDisabled = true;
      try {
        this.queryParams.extractApproveStatus = "8";
        this.queryParams.userId = this.form.userId;
        this.queryParams.randomUnittypeId = this.form.randomUnittypeId;
        const res = await getExtractList(this.queryParams);
        if (res.code === 200) {
          const result = res.rows;
          for (var i = 0; i < result.length; i++) {
            let obj = result[i];
            for (const j in obj) {
              if (obj[j] === null) {
                // console.log(3333,obj[j])
                obj[j] = "";
              } else {
                // console.log(2222,obj[j])
                obj[j] = obj[j];
              }
            }
          }
          this.articleList = result;
          this.totalSize = res.total;
        }
      } catch (e) {
        this.$message.error(e);
      } finally {
        //this.tableLoading = false;
        this.isPaginationDisabled = false;
      }
    },
    // 删除文件之前
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    // 删除文件
    handleRemove(file, fileList) {
      const index = this.fileList.find((item) => item.uid === file.uid);
      const i = this.fileList.find((item) => item === file.url);
      this.fileList.splice(index, 1);
      this.reviewImg.splice(i, 1);
      this.saveItem.fileUrl = this.fileList.map((item) => item.url);
    },
    // 超过上传个数
    onExceed() {
      this.$message.error("最多只能上传一个文件");
    },
    // 上传文件，获取文件地址
    async uploadFile(eleFile) {
      // console.log(eleFile);
      const file = eleFile.file;
      let fileType = file.name.split(".");
      fileType = fileType[fileType.length - 1];
      if (file.size > 10 * 1024 * 1024) {
        this.$message.error("文件大小不能超过10MB");
        return;
      }
      if (!this.acceptType.includes(fileType)) {
        this.$message.error("文件类型不正确");
        let uid = file.uid;
        let idx = this.$refs.uploadFile.uploadFiles.findIndex(
          (item) => item.id === uid
        );
        this.$refs.uploadFiles.splice(idx, 1);
        return;
      }
      const fd = new FormData();
      fd.append("file", file);
      try {
        const res = await service.post("/common/upload", fd, {
          headers: { "content-type": "multipart/form-data" },
        });
        if (res.code === 200) {
          this.fileList.push({
            name: file.name,
            url: res.url,
          });
          if (this.imageType.includes(fileType)) {
            this.reviewImg = [res.url];
          }
          this.saveData.fileUrl = this.fileList.map((item) => item.url);
          this.$message({
            message: "上传成功",
            type: "success",
          });
        }
      } catch (e) {
        this.$message.error(e);
      }
    },
    // 当表格的当前行发生变化的时候会触发该事件
    currentRowChange(currentRow) {
      this.currentRow = currentRow;
      if(currentRow) {
        (this.quotationConfirm = [
        {
          name: "申请单位",
          detailInfo: currentRow.createBy,
          showTwo: true,
        },
        {
          name: "项目名称",
          detailInfo: currentRow.extractItem,
          showTwo: true,
        },
        {
          name: "建设地址",
          detailInfo: currentRow.extractAddress,
          showTwo: true,
        },
        {
          name: "建设周期",
          detailInfo: currentRow.extractPeriod,
          showTwo: true,
        },
        {
          name: "工程费用（万元）",
          detailInfo: currentRow.extractPrice,
          showTwo: true,
        },
        {
          name: "工程概况",
          detailInfo: currentRow.projectOverview,
          showTwo: true,
        },
      ]),
        (this.price = [
          {
            name: "中介机构服务费（万元）",
            detailInfo: currentRow.maxPrice,
            showTwo: true,
          },
          {
            name: "抽取要求",
            detailInfo: currentRow.extractBanReason, //不确定
            showTwo: true,
          },
          {
            name: "经办人",
            detailInfo: currentRow.extractCharge,
            showTwo: true,
          },
          {
            name: "联系电话",
            detailInfo: currentRow.extractPhone,
            showTwo: true,
          },
          {
            name: "抽  取  人",
            detailInfo: currentRow.extractUser,
            showTwo: true,
          },
          {
            name: "抽取地点",
            detailInfo: currentRow.extractPlace,
            showTwo: true,
          },
          {
            name: "抽取要求",
            detailInfo: currentRow.extractBanReason, //不确定
            showTwo: true,
          },
          {
            name: "抽  取  库",
            detailInfo: currentRow.unitTypeName,
            showTwo: true,
          },
          {
            name: "业务类型",
            detailInfo: currentRow.extractBusinessType,
            showTwo: true,
          },
          {
            name: "签字表",
            detailInfo: currentRow.extractSignUrl,
            showimg: true,
            showTwo: true,
          },
          {
            name: "是否需要驻场服务",
            detailInfo: currentRow.extractResident == 0 ? "是" : "否",
            showTwo: false,
          },
          {
            name: "驻场服务人数(至少)",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractResidentNumber
                : "",
            showTwo: true,
          },
          {
            name: "完成时限",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractLimitedTime
                : "",
            showTwo: true,
          },
          {
            name: "驻 场 要 求",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractStationRequire
                : "",
            showTwo: false,
          },
          {
            name: "抽取单位数",
            detailInfo: currentRow.extractNumber,
            showTwo: false,
          },
        ]);
      }
    },
    // 获取单位名称等数据
    async loadExtractArticle(row) {
      this.commentDialogVisible = true;
      //  调接口，将项目id currentRow.extractId传给后台，获取当前行的评分数据
      getScore().then((res) => {
        // console.log(res);
        this.saveData.radioList = res.rows;
        this.saveData.radioList.forEach((item) => {
          if (item.whetherDeduct === null) {
            item.whetherDeduct = "0";
          }
        });
      });
      const extractId = row.extractId || this.ids;
      const res = await getExtractArticle({ randomBan: 3, extractId });
      const companyInfo = res.rows;
      for (var i = 0; i < companyInfo.length; i++) {
        const obj = companyInfo[i];
        for (const j in obj) {
          if (obj[j] === null) {
            obj[j] = "";
          } else {
            obj[j] = obj[j];
          }
        }
      }
      this.companyInfo = companyInfo;
      companyInfo.forEach((item) => {
        this.simpleTableData.list.push([
          item.randomUnitName,
          this.handleRandomBan(item.randomBan),
          {
            handleTile: "查看详情",
            org: item,
            callBack: (currentRow, index) => {
              // console.log("currentRow",currentRow,"index",index)
              this.currentObj = currentRow[currentRow.length - 1].org;
              this.detailDialogVisible = true;
              // 获取单位详细信息
              getUnit(this.currentObj.randomUnitId).then((res) => {
                const relativeInfo = res.data;
                for (const j in relativeInfo) {
                  if (relativeInfo[j] === null) {
                    relativeInfo[j] = "";
                  } else {
                    relativeInfo[j] = relativeInfo[j];
                  }
                }
                // 传给组件展示的公司信息
                this.unitInfo = relativeInfo;
              });
            },
          },
        ]);
        for (var i = 0; i < this.simpleTableData.list.length; i++) {
          if (i >= 1) {
            this.simpleTableData.list.splice(0, 1);
          }
        }
      });
    },

    // 关闭项目评价弹窗
    closeCommentDialog() {
      this.fileList = [];
      this.saveData.fileUrl = [];
      this.imgUrl = [];
      this.saveData.deductReason = "";
      (this.saveData.endDate = ""), this.loadExtractList();
    },
    //单位选择select改变方法
    UnitTypeChange(value) {
      //让table显现出来
      //查询table数据
      this.UnitqueryParams.unitType = value;
      this.UnitqueryParams.extractId = this.form.extractId;
      //console.log('extractId' + this.UnitqueryParams.extractId);
      randomlist(this.UnitqueryParams).then((response) => {
        this.unitList = response.rows;
        this.loading = false;
      });
    },
    // 处理公司状态
    handleRandomBan(val) {
      switch (val) {
        case "0":
          return "正常";
        case "1":
          return "排除";
        case "2":
          return "中签";
        case "3":
          return "中标";
        case "4":
          return "未中标";
        case "5":
          return "废除报价";
      }
    },
    // 点击项目评价弹窗保存按钮
    async saveInfo() {
      this.commentDialogVisible = false;
      // this.saveData.fileUrl = this.saveData.fileUrl.join(',');
      // console.log(this.saveData.fileUrl);
      // const obj = {
      // 	extractId: this.currentRow.extractId,
      // 	extractItem: this.currentRow.extractItem,
      // 	randomUnitId: this.companyInfo[0].randomUnitId,
      // 	randomUnitName: this.companyInfo[0].randomUnitName,
      // 	deductReason: this.saveData.deductReason,
      // 	endDate: this.saveData.endDate,
      // 	fileUrl: this.saveData.fileUrl,
      // 	deductList: this.saveData.radioList,
      // 	extractApproveStatus:'8'
      // };
      // // 违规扣分
      // try {
      // 	const query = JSON.stringify(obj);
      // 	const res = await saveDeduction(query);
      // 	this.$message.success(res.msg);
      // } catch (e) {
      // 	this.$message.error(e);
      // }
    },
    async loadExtractReview(row) {
      this.reviewRow = row;
      row.markSheet
        ? (this.reviewImg = [row.markSheet])
        : (this.reviewImg = []);
      this.reviewVisible = true;
      //  调接口，将项目id currentRow.extractId传给后台，获取当前行的评分数据
      getScore().then((res) => {
        this.saveData.radioList = res.rows;
        this.saveData.radioList.forEach((item) => {
          if (item.whetherDeduct === null) {
            item.whetherDeduct = "0";
          }
        });
      });
      const extractId = row.extractId || this.ids;
      const res = await getExtractArticle({ randomBan: 3, extractId });
      // this.saveData.radioList = res.rows[0].endTime;
      this.saveData.radioList.forEach((item, index )=> item.whetherDeduct = res.rows[0].scoreindices[index].whetherDeduct);
      this.saveItem.projectStartTime = res.rows[0].startTime;
      this.saveItem.projectEndTime = res.rows[0].endTime;
      this.saveItem.deductReason = res.rows[0].scoreindices[0]?.remark;
      this.reviewRow = res.rows[0];
      this.reviewRow.settleAmount = row.settleAmount;
      const companyInfo = res.rows;
      for (var i = 0; i < companyInfo.length; i++) {
        const obj = companyInfo[i];
        for (const j in obj) {
          if (obj[j] === null) {
            obj[j] = "";
          } else {
            obj[j] = obj[j];
          }
        }
      }
      this.companyInfo = companyInfo;
      companyInfo.forEach((item) => {
        this.simpleTableData.list.push([
          item.randomUnitName,
          this.handleRandomBan(item.randomBan),
          item.bidamount === null ? "" : item.bidamount,
          item.createTime,
          {
            handleTile: "项目评价",
            org: item,
            callBack: (currentRow, index) => {
              // console.log("currentRow",currentRow,"index",index)
              this.currentObj = currentRow[currentRow.length - 1].org;
              this.detailDialogVisible = true;
              // 获取单位详细信息
              getUnit(this.currentObj.randomUnitId).then((res) => {
                const relativeInfo = res.data;
                for (const j in relativeInfo) {
                  if (relativeInfo[j] === null) {
                    relativeInfo[j] = "";
                  } else {
                    relativeInfo[j] = relativeInfo[j];
                  }
                }
                this.unitInfo = relativeInfo;
              });
            },
          },
        ]);
        for (var i = 0; i < this.simpleTableData.list.length; i++) {
          if (i >= 1) {
            this.simpleTableData.list.splice(0, 1);
          }
        }
      });
    },
    currentDeductScore() {
      let deduct = 0;
      this.saveData.radioList.forEach((item) => {
        if (item.whetherDeduct === "1") {
          deduct += 2;
        }
      });
      return deduct;
    },
    async saveReview() {
      // console.log(844,this.saveData.fileUrl)
      // this.saveData.fileUrl = this.saveData.fileUrl.join(",");
      let extract;
      if (this.reviewRow.isNormal == 0) {
        if (this.reviewRow.settleAmount <= 0) {
          this.$message.error("结算金额需大于0");
          return;
        }
        const scoreindexList = this.saveData.radioList;
        const deductFlag = scoreindexList.some(
          (item) => item.whetherDeduct == 1
        );
        if (deductFlag && this.reviewImg.length == 0) {
          this.$message.error("包含违规扣分，请上传评分表");
          return;
        }
        if (
          this.currentDeductScore() > 0 &&
          this.saveItem.deductReason.length < 1
        ) {
          this.$message.error("包含违规扣分，请填写备注");
          return;
        }
        if (!this.saveItem.projectStartTime) {
          this.$message.error("请选择开始日期");
          return;
        }
        if (!this.saveItem.projectEndTime) {
          this.$message.error("请选择结束日期");
          return;
        }
        scoreindexList.forEach((item) => {
          item.extractId = this.reviewRow.extractId;
          item.extractItem = this.reviewRow.extractItem;
          item.remark = this.saveItem.deductReason;
        });
        extract = {
          extractId: this.reviewRow.extractId,
          extractItem: this.reviewRow.extractItem,
          projectStartTime: this.saveItem.projectStartTime,
          projectEndTime: this.saveItem.projectEndTime,
          scoreindexList,
          markSheet: this.reviewImg.toString(),
          settleAmount: this.reviewRow.settleAmount,
          isNormal: this.reviewRow.isNormal,
          deductReason: this.saveItem.deductReason
        };
      } else {
        extract = {
          extractId: this.reviewRow.extractId,
          isNormal: this.reviewRow.isNormal,
          abnormalReason: this.saveItem.deductReason
        }
      }
      evaluate(extract)
        .then((res) => {
          this.$message.success(res.msg);
          this.reviewVisible = false;
          this.reviewRow = {};
          this.saveItem = {};
          this.imgUrl = [];
          this.loadExtractList();
        })
        .catch((e) => {
          this.$message.error(e);
        });
    },
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有项目申请数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportExtract(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
  filters: {
    formatStatus(val) {
      switch (val) {
        case "0":
          return "未提交";
        case "1":
          return "申请中";
        case "2":
          return "审批通过";
        case "3":
          return "审批拒绝";
        case "4":
          return "已抽取";
        case "5":
          return "已发布";
        case "6":
          return "待确认";
        case "7":
          return "项目执行中";
        case "8":
          return "项目完成";
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.appraise-container {
  padding: 0 20px;
  .form-header {
    margin: 0;
    width: 100%;
    display: flex;
    align-items: center;
    border-bottom: unset;
    padding-top: 20px;
    .el-form-item {
      .search-btn {
        background-color: #1890ff;
      }
      .el-form-item__content {
        margin-left: 0 !important;
      }
    }
    .btns {
      margin-left: -50px;
    }
  }
  .pagination {
    display: flex;
    justify-content: flex-end;
    padding-top: 15px;
  }
}
::v-deep .el-table .cell {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
::v-deep .el-table .cell:hover {
  white-space: normal;
}
.score-wrap {
  padding: 15px;
  display: flex;
  flex-direction: column;
  label {
    width: 103px;
    text-align: right;
    padding-right: 8px;
  }
  .time-wrap {
    display: flex;
    width: 88%;
    justify-content: space-between;
    padding-bottom: 10px;
    .begin-time,
    .end-time {
      display: flex;
      align-items: center;
      ::v-deep .el-input__inner {
        padding: 10px;
      }
    }
  }
  .select-file {
    display: flex;
    > label {
      width: 100px;
    }
    > .remain {
      width: calc(100% - 100px);
    }
  }
  .deduction-wrap {
    display: flex;
    align-items: baseline;
    > ul {
      li {
        list-style: none;
        display: flex;
        padding: 5px 0;
        > .deduction-title {
          width: 50%;
        }
      }
    }
  }
  .deduction-reason-wrap {
    display: flex;
    > textarea {
      width: 80%;
    }
  }
}
::v-deep .el-dialog__title {
  font-weight: 600;
}
::v-deep .el-dialog__body {
  padding: 0px 20px 30px 20px;
}
::v-deep .el-icon-date:before {
  content: "";
}
::v-deep .el-upload {
  text-align: left;
}
::v-deep .el-upload-list {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  .el-upload-list__item {
    width: 50%;
  }
}
.uploadimg-wrap {
  padding-top: 10px;
  > .uploadimg {
    margin-right: 10px;
    margin-bottom: 8px;
  }
}
.must {
  color: red;
  margin-right: 5px;
}
.form-img-out {
  width: 130px;
  height: 130px;
}
.form-img-line {
  width: 500px;
  height: 500px;
}
.form-dialog {
  text-align: center;
}
.current-score {
  color: #da0620;
  padding-left: 140px;
  font-size: 18px;
  font-weight: 600;
}
</style>
